package com.itheima.service.impl;




import com.itheima.mapper.KsClassMapper;
import com.itheima.mapper.UserMapper;
import com.itheima.pojo.KsClass;
import com.itheima.pojo.Student;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
*
*/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private KsClassMapper ksClassMapper;

    public List<KsClass> findType(String mobile) {
        User user = userMapper.selectMobile(mobile);
        if(user==null){
            return null;
        }
        Integer roleId = user.getRoleId();
        if(roleId==1){
            List<KsClass> list = ksClassMapper.selectAllClass();
            return list;
        }
        return null;
    }

    public User login(User user) {
        String name = user.getName();
        String password = user.getPassword();
        if(name==null){
            return null;
        }
        User user1 = userMapper.selectByName(name);
        String password1 = user1.getPassword();
        if (password.equals(password1)){
            return user1;
        }
        return null;
    }

    public List<Student> findByClassId() {
        List<Student> students = userMapper.selectByClassId();
        return students;
    }

    public int addIntegral(Student student) {
        Integer integral = student.getIntegral();
        Integer id = student.getId();
        Student student1 = userMapper.selectByStudentId(id);
        Integer integral1 = student1.getIntegral();
        student1.setIntegral(integral+integral1);
        int count = userMapper.updateIntegral(student1);
        return count;
    }
}
